﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Expo.Training.DataAccess.Activity;

public partial class Activity_ActivityCourseManagement : PageBase
{
    private Guid _activityID;
    private ActivityEntity _mdlActivity;

    protected void Page_Load(object sender, EventArgs e)
    {
        _activityID = new Guid(Request.QueryString["id"].ToString());

        if (!IsPostBack)
        {
            _mdlActivity = ActivityModule.GetActivity(_activityID);
            this.ltlActivityTitle.Text = _mdlActivity.ActivityTitle;
            this.lnkBack.NavigateUrl = "AddActivityCourse.aspx?id=" + _activityID;

            Bind();
        }

        
    }

    #region 绑定已关联课程
    private void Bind()
    {
        List<ActivityCourseDetailsEntity> _list = ActivityModule.GetCoursesDetailsByActivityID(_activityID);

        if (_list.Count > 0)
        {
            this.rpt_Course.DataSource = _list;
            this.rpt_Course.DataBind();
        }
        else
        {
            this.dv_NoResult.Visible = true;
        }
    }
    #endregion

    #region 删除关联
    protected void rpt_Course_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            Guid _courseId = new Guid(e.CommandArgument.ToString());

            try
            {
                if (ActivityModule.DeleteActivityCourse(_activityID, _courseId))
                {
                    this.AddEndScript("delete succes", "alert('删除关联成功！');location.href='ActivityCourseManagement.aspx'");
                    Bind();
                }
                else
                {
                    this.AddEndScript("error", "alert('删除操作出错，请重试！');");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
    #endregion
}
